<?php
namespace Controllers;
class BaseController {

    protected function render ($tpl, $data = []) {
        $tplPath = './Views/' . $tpl . '.php';
        if (!file_exists($tplPath)) {
            echo 'The tpl ' . $tpl . ' is not exists!';
            exit;
        }
        extract($data); // ['username' => 'zhangsan']  $username = 'zhangsan'
        include_once $tplPath;
    }


    protected function error($message) {
        return '<script>alert("' . $message . '"); window.history.back()</script>';
    }

    protected function success($message, $url) {
        return '<script>alert("' . $message . '"); window.location.href="' . $url . '"</script>';
    }
}